package com.yy.train.ticket.train.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.train.ticket.into.LineLinkRadio;
import com.yy.train.ticket.into.page.LinePage;
import com.yy.train.ticket.into.page.RunDatePage;
import com.yy.train.ticket.train.entity.TtLineEntity;
import com.yy.train.ticket.train.entity.TtLineLinkEntity;
import com.yy.train.ticket.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yy.train.ticket.train.entity.TtTrainRunSeatEntity;
import com.yy.train.ticket.train.service.TtTrainRunSeatService;




/**
 * 座位
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-10-08 16:04:23
 */
@RestController
@RequestMapping("tt/runseat")
public class TtTrainRunSeatController {
    @Autowired
    private TtTrainRunSeatService ttTrainRunSeatService;

    /**
     * 列表
     */
    @GetMapping("/list/{runDateId}")
    public R list(@PathVariable("runDateId")  Long runDateId){
        return R.ok(this.ttTrainRunSeatService.list(Wrappers.<TtTrainRunSeatEntity>lambdaQuery()
                .eq(StringUtils.checkValNotNull(runDateId),TtTrainRunSeatEntity::getRunDateId,runDateId)));

    }
    @PostMapping("/page")
    public R page(@RequestBody RunDatePage trainPage){
        LambdaQueryWrapper<TtTrainRunSeatEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(StringUtils.checkValNotNull(trainPage.getRunDateId()),TtTrainRunSeatEntity::getRunDateId,trainPage.getRunDateId())
                .eq(StringUtils.checkValNotNull(trainPage.getBoxId()),TtTrainRunSeatEntity::getBoxId,trainPage.getBoxId())
        ;

        Page<TtTrainRunSeatEntity> pages = new Page<TtTrainRunSeatEntity>(trainPage.getPageNum(), trainPage.getPageSize());
        IPage<TtTrainRunSeatEntity> iPage = ttTrainRunSeatService.page(pages, lambdaQueryWrapper);
        return R.ok(iPage);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{seatId}")
    public R info(@PathVariable("seatId") Long seatId){
		TtTrainRunSeatEntity ttTrainRunSeat = ttTrainRunSeatService.getById(seatId);

        return R.ok().put("ttTrainRunSeat", ttTrainRunSeat);
    }
    @GetMapping("/number/{runDateId}")
    public R number(@PathVariable("runDateId") Long runDateId){
        return ttTrainRunSeatService.getNumberBoxSeat(runDateId);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TtTrainRunSeatEntity ttTrainRunSeat) throws InterruptedException {
        return ttTrainRunSeatService.saveTrainRunSeat(ttTrainRunSeat);

       // return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TtTrainRunSeatEntity ttTrainRunSeat){
		ttTrainRunSeatService.updateById(ttTrainRunSeat);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List<Long> seatIds){
		ttTrainRunSeatService.removeByIds(seatIds);
        return R.ok();
    }

}
